package org.springsource.domain;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonManagedReference;

@Entity
@Table(name = "Team")
public class Team implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -644244819290702602L;
	@Id
	@Column(name = "id", nullable = false)
	private Long id;
	
	@Column(name = "name")
	private String name;
	
	
	@JsonBackReference
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "countryCode", insertable = false, updatable = false)
	private Country country;
	
	@JsonIgnore
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "levelId", insertable = false, updatable = false)
	private Level level;
	
	@JsonManagedReference
	@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
	@JoinColumn(name = "team")
	private List<Player> players;

	public Team() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public Level getLevel() {
		return level;
	}

	public void setLevel(Level level) {
		this.level = level;
	}

	public List<Player> getPlayers() {
		return players;
	}

	@Override
	public String toString() {
		return "Team [id=" + id + ", name=" + name + ", country=" + country
				+ ", level=" + level + ", players=" + players + "]";
	}

	public void setPlayers(List<Player> players) {
		this.players = players;
	}

	public String getValue() {
		return name.replace(" ", "-").toLowerCase();
	}

}
